package com.my.study.common;

import com.my.study.common.message.Message;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;

/**
 * @author Carlos
 * @version 1.0
 * @Description 服务端连接客户端线程
 * @date 2021/7/18 15:09
 **/
public class ServerConnectClientThread extends Thread{

    private Socket socket;
    private String userId;

    public ServerConnectClientThread(Socket socket, String userId) {
        this.socket = socket;
        this.userId = userId;
    }

    @Override
    public void run() {
        while (true) {
            try {
                System.out.println("服务器与客户端保持通信...");
                ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
                Message message = (Message) ois.readObject();
                // TODO 使用message

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


}
